import java.awt.*;


public class FreehandDrawingObject implements IDrawingObject{

	pointLink first;
	pointLink last;
	Color myColor;
	int top;
	int bottom;
	int left;
	int right;
	
	public FreehandDrawingObject(Point p, Color c){
		right=p.x;
		left=p.x;
		top=p.y;
		bottom=p.y;
		first=new pointLink(p);
		last=first;
		myColor=c;
		//System.out.println("made new fdo");
	}
    
	public void drawMe(Graphics g) {	
		//System.out.println("draw me");
		Color tempColor = g.getColor();
		g.setColor(myColor);
		pointLink current=first;
		while(current.next!=null){
			g.drawLine(current.p.x,current.p.y,current.next.p.x, current.next.p.y);
			current=current.next;
		}
		g.setColor(tempColor);
	}
	
	public boolean isPointInObject(Point p){
		return p.x<=right && p.x>=left && p.y>=top && p.y<=bottom;
	}
	
	public void add(Point p){
		if(p.x>right){ right=p.x;}
		if(p.y<top){ top=p.y;}
		if(p.x<left){ left=p.x;}
		if(p.y>bottom){ bottom=p.y;}
		
		last.next=new pointLink(p);
		last=last.next;
	}

	public int getHeight() {
		return bottom-top;
	}

	public int getTop() {
		return top;
	}

	public int getWidth() {
		return right-left;
	}
	
	public int getLeft(){
		return left;
	}
	public void setmycolor(Color c){
		myColor=c;
	}
}

class pointLink{
	public pointLink(Point p){
		this.p=p;
		this.next=null;
	}
	public Point p;
	public pointLink next;
}